{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Contribute\n",
    "\n",
    "Before we can accept contributions, you need to become a CLAed contributor.\n",
    "E-mail a signed copy of the\n",
    "[CLAI](https://github.com/openpifpaf/openpifpaf/blob/main/docs/CLAI.txt)\n",
    "(and if applicable the\n",
    "[CLAC](https://github.com/openpifpaf/openpifpaf/blob/main/docs/CLAC.txt))\n",
    "as PDF file to research@svenkreiss.com."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "(modify-code)=\n",
    "## Modify Code\n",
    "\n",
    "For development of the openpifpaf source code itself, you need to clone this repository and then:\n",
    "\n",
    "```sh\n",
    "pip3 install numpy cython\n",
    "pip3 install --editable '.[dev,train,test]'\n",
    "```\n",
    "\n",
    "The last command installs the Python package in the current directory\n",
    "(signified by the dot) with the optional dependencies needed for training and\n",
    "testing. If you modify `functional.pyx`, run this last command again which\n",
    "recompiles the static code.\n",
    "\n",
    "Develop your features in separate feature branches. \n",
    "Create a pull request with your suggested changes. Make sure your code passes\n",
    "`pytest`, `pylint` and `pycodestyle` checks:\n",
    "\n",
    "```sh\n",
    "pylint openpifpaf\n",
    "pycodestyle openpifpaf\n",
    "pytest\n",
    "\n",
    "cd guide\n",
    "python download_data.py\n",
    "pytest --nbval-lax --current-env *.ipynb\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Things to Contribute\n",
    "\n",
    "This is a research project and changing fast. Contributions can be in many areas:\n",
    "* Add a new dataset?\n",
    "* Add a new base network? \n",
    "* Try a different loss? \n",
    "* Try a better multi-task strategy?\n",
    "* Try a different head architecture? \n",
    "* Add a new task? \n",
    "* Run on new hardware (mobile phones, embedded devices, ...)? \n",
    "* Improve training schedule/procedure?\n",
    "* Use it to build an app?\n",
    "* Improve documentation (!!)\n",
    "* ..."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Missing Dependencies\n",
    "\n",
    "OpenPifPaf has few core requirements so that you can run it efficiently on servers without graphical interface. \n",
    "Sometimes, you just want to install all possible dependencies. Those are provided as \"extra\" requirements. \n",
    "Use the following `pip3` command to install all extras."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [],
   "source": [
    "# NO CODE\n",
    "import sys\n",
    "if sys.version_info >= (3, 8):\n",
    "    import importlib.metadata\n",
    "    extras = importlib.metadata.metadata('openpifpaf').get_all('Provides-Extra')\n",
    "    print(f'pip3 install \"openpifpaf[{\",\".join(extras)}]\"')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Your Project and OpenPifPaf\n",
    "\n",
    "Let us know about your open source projects. We would like to feature them in our \"related projects\" section. \n",
    "\n",
    "The simplest way to integrate with OpenPifPaf is to write a plugin. If some functionality is not possible through our plugin architecture, open an issue to discuss and if necessary send us a pull request that enables the missing feature you need.\n",
    "\n",
    "If you do need to make a copy of OpenPifPaf, you must respect our license."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Build Guide\n",
    "\n",
    "```sh\n",
    "pip install jupyter-book\n",
    "cd guide\n",
    "jb build .\n",
    "```\n",
    "\n",
    "If you encounter issues with the kernel spec in a notebook, open the notebook\n",
    "with a text editor and find `metadata.kernelspec.name` and set it to `python3`.\n",
    "\n",
    "Alternatively, you can patch your local package yourself. Open \n",
    "`venv/lib/python3.9/site-packages/jupyter_cache/executors/utils.py`\n",
    "in your editor and add `kernel_name='python3'` to the arguments of `nbexecute()`\n",
    "[here](https://github.com/executablebooks/jupyter-cache/blob/1431ed72961fabc2f09a13553b0aa45f4c8a7c23/jupyter_cache/executors/utils.py#L56).\n",
    "\n",
    "Alternatively, for continuous integration, the `kernel_name` is replace in the json of the \n",
    "Jupyter Notebook before executing jupyter-book \n",
    "[here](https://github.com/openpifpaf/openpifpaf/blob/6db797205cd082bf7a80e967372957e56c9835fb/.github/workflows/deploy-guide.yml#L47).\n",
    "Only use this operation on a discardable copy as `jq` changes all formatting.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Build Environment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "pip freeze"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "python -m openpifpaf.predict --version"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": ""
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
